﻿using System.Collections.Generic;
/// <summary>
/// 操作指令
/// </summary>
public class OpOrder
{
    /// <summary>
    /// 操作指令
    /// </summary>
    public uint keyCode = 0;
    /// <summary>
    /// 指令开始或结束
    /// （对应按键的按下与抬起，考虑到按住按键就发的话，会导致指令过多，建议只发开始和结束）
    /// </summary>
    public bool isBegin = true;
    /// <summary>
    /// 指令执行的时间点ms
    /// </summary>
    public uint exeTimePoint = 0;
}

/// <summary>
/// 客户端上传操作指令
/// </summary>
class MsgKeyInputReq : BaseProtocol
{
    /// <summary>
    /// 指令所属客户端id，这里不用父类里的数值，不确定是不是和原先设计一个含义
    /// </summary>
    public uint clientId = 0;
    public uint count = 0;
    //考虑到一个指令一条协议可能导致发送协议数过多，支持一次发送多个指令
    public List<OpOrder> orderList = new List<OpOrder>();
    public override int ProtocolID
    {
        get
        {
            return 21104;
        }
    }
    /// <summary>
    /// Client
    /// </summary>
    protected override void WriteParams()
    {
        Write(clientId);
        count = (uint)orderList.Count;
        Write(count);
        for (int i = 0; i < count; i++)
        {
            Write(orderList[i].keyCode);
            Write(orderList[i].isBegin);
            Write(orderList[i].exeTimePoint);
        }  
    }
    /// <summary>
    /// Server
    /// </summary>
    protected override void ReadParams()
    {
        clientId = ReadUInt();
        count = ReadUInt();
        orderList = new List<OpOrder>();
        for (int i = 0; i < count; i++)
        {
            OpOrder order = new OpOrder();
            order.keyCode = ReadUInt();
            order.isBegin = ReadBool();
            order.exeTimePoint = ReadUInt();
            orderList.Add(order);
        }
    }
}

